<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JS 事件机制</title>
  <style>
  #parent {
    width: 200px;
    height: 200px;
    background-color: red;
  }
  #child {
    width: 100px;
    height: 100px;
    background-color: blue;
  }
  </style>
</head>
<!-- 不利于维护 -->
<body onclick="alert('橘子')">
  <div id="parent">
    <div id="child"></div>
  </div>
  <script>
  document.getElementById('parent').addEventListener('click', function() {
    console.log('parent click');
  },false)
  document.getElementById('child').addEventListener('click', function() {
    console.log('child click');
  },false)
  </script>
</body>
</html>